
package com.yuan.model;

import com.yuan.prefence.FileConstants;
import com.yuan.prefence.UrlConstants;
import com.yuan.unit.FileUtils;
import com.yuan.unit.HttpUtils;
import com.yuan.unit.JsonUtils;

import android.content.Context;
import android.text.TextUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * 请假申请 entity. @author MyEclipse Persistence Tools
 */

@SuppressWarnings("serial")
public class M请假申请 implements java.io.Serializable {

    // Fields

    private Integer id = -1;
    private String 填表人;
    private String 申请人;
    private String 姓名;
    private String 所属队室;
    private String 请假类别;
    private String 开始;
    private String 结束;
    private Float 总时间;
    private String willread;
    private String readed;
    private String 请假理由;
    private String 意见;
    private String 申请日期;
    private String 状态;

    private static M请假申请 sInstance;

    public static M请假申请 getInstance() {
        if (sInstance == null) {
            synchronized (M请假申请.class) {
                if (sInstance == null) {
                    sInstance = new M请假申请();
                }
            }
        }
        return sInstance;
    }

    public void setFromMap(Map<?, ?> map) {
        try {
            this.id = (Integer) map.get("id");
            this.填表人 = (String) map.get("填表人");
            this.申请人 = (String) map.get("申请人");
            this.姓名 = (String) map.get("姓名");
            this.所属队室 = (String) map.get("所属队室");
            this.请假类别 = (String) map.get("请假类别");
            this.开始 = (String) map.get("开始");
            this.结束 = (String) map.get("结束");
            this.总时间 = (Float) map.get("总时间");
            this.willread = (String) map.get("willread");
            this.readed = (String) map.get("readed");
            this.请假理由 = (String) map.get("请假理由");
            this.意见 = (String) map.get("意见");
            this.申请日期 = (String) map.get("申请日期");
            this.状态 = (String) map.get("状态");
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    private M请假申请() {
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String get填表人() {
        return this.填表人;
    }

    public void set填表人(String 填表人) {
        this.填表人 = 填表人;
    }

    public String get申请人() {
        return this.申请人;
    }

    public void set申请人(String 申请人) {
        this.申请人 = 申请人;
    }

    public String get姓名() {
        return this.姓名;
    }

    public void set姓名(String 姓名) {
        this.姓名 = 姓名;
    }

    public String get所属队室() {
        return this.所属队室;
    }

    public void set所属队室(String 所属队室) {
        this.所属队室 = 所属队室;
    }

    public String get请假类别() {
        return this.请假类别;
    }

    public void set请假类别(String 请假类别) {
        this.请假类别 = 请假类别;
    }

    public String get开始() {
        return this.开始;
    }

    public void set开始(String 开始) {
        this.开始 = 开始;
    }

    public String get结束() {
        return this.结束;
    }

    public void set结束(String 结束) {
        this.结束 = 结束;
    }

    public Float get总时间() {
        return this.总时间;
    }

    public void set总时间(Float 总时间) {
        this.总时间 = 总时间;
    }

    public String getWillread() {
        return this.willread;
    }

    public void setWillread(String willread) {
        this.willread = willread;
    }

    public String getReaded() {
        return this.readed;
    }

    public void setReaded(String readed) {
        this.readed = readed;
    }

    public String get请假理由() {
        return this.请假理由;
    }

    public void set请假理由(String 请假理由) {
        this.请假理由 = 请假理由;
    }

    public String get意见() {
        return this.意见;
    }

    public void set意见(String 意见) {
        this.意见 = 意见;
    }

    public String get申请日期() {
        return this.申请日期;
    }

    public void set申请日期(String 申请日期) {
        this.申请日期 = 申请日期;
    }

    public String get状态() {
        return this.状态;
    }

    public void set状态(String 状态) {
        this.状态 = 状态;
    }

    /**
     * 发送请假并返回请假的json对象
     * 
     * @param mContext
     * @return
     */
    public boolean askForLeave(Context mContext) {
        String str = null;
        if (TextUtils.isEmpty(申请人) || TextUtils.isEmpty(开始)
                || TextUtils.isEmpty(结束) || TextUtils.isEmpty(请假理由))
        {
            return false;
        }
        String url = String.format(UrlConstants.ASKLEAVEURL, 申请人, 请假类别, 开始, 结束, 请假理由);
        try {
            str = HttpUtils.getUrlContent(mContext, url, "UTF-8");
            HashMap<?, ?> mHashMap = JsonUtils.getMap0(str);
            FileUtils.Serializable2File(mHashMap, FileConstants.SERIALIZABLE_请假申请);
            return true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

    public boolean getAllLeaveAccount(Context mContext) {
        String str = null;
        if (TextUtils.isEmpty(申请人))
        {
            return false;
        }
        String url = String.format(UrlConstants.GETALLLEAVEURL, 申请人);
        try {
            str = HttpUtils.getUrlContent(mContext, url, "UTF-8");
            ArrayList<?> mArrayList = JsonUtils.getList(str);
            FileUtils.Serializable2File(mArrayList, FileConstants.SERIALIZABLE_请假申请记录);
            return true;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

    public boolean cancelLeave(Context mContext) {
        String str = null;
        if (id == -1)
        {
            return false;
        }
        String url = String.format(UrlConstants.CANCELLEAVEURL, id);
        try {
            str = HttpUtils.getUrlContent(mContext, url, "UTF-8");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (str.equals("删除成功"))
        {
            getAllLeaveAccount(mContext);
            return true;
        }
        return false;
    }
}
